<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>SoapFault constructor</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.soapfault.html">« SoapFault</a></li>
      <li style="float: right;"><a href="soapfault.tostring.html">SoapFault::__toString »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.soapfault.html">SoapFault</a></li>
    <li>SoapFault constructor</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="soapfault.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SoapFault::__construct</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SoapFault::__construct</span> &mdash; <span class="dc-title">SoapFault constructor</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-soapfault.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SoapFault::__construct</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$code</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$actor</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$details</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$name</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$headerFault</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>)</div>

  <p class="para rdfs-comment">
   This class is used to send SOAP fault responses from the PHP handler.
   <code class="parameter">faultcode</code>, <code class="parameter">faultstring</code>,
   <code class="parameter">faultactor</code> and <code class="parameter">detail</code> are
   standard elements of a SOAP Fault.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-soapfault.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">faultcode</code></dt>

     <dd>

      <p class="para">
       The error code of the <span class="classname"><a href="class.soapfault.html" class="classname">SoapFault</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">faultstring</code></dt>

     <dd>

      <p class="para">
       The error message of the <span class="classname"><a href="class.soapfault.html" class="classname">SoapFault</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">faultactor</code></dt>

     <dd>

      <p class="para">
       A string identifying the actor that caused the error.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">detail</code></dt>

     <dd>

      <p class="para">
       More details about the cause of the error.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">faultname</code></dt>

     <dd>

      <p class="para">
       Can be used to select the proper fault encoding from WSDL.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">headerfault</code></dt>

     <dd>

      <p class="para">
       Can be used during SOAP header handling to report an error in the
       response header.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-soapfault.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5346">
    <p><strong>示例 #1 Some examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #0000BB">$x</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapFault</span><span style="color: #007700">(</span><span style="color: #DD0000">"Server"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Some&nbsp;error&nbsp;message"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapServer</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'uri'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"http://test-uri/"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   It is possible to use PHP exception mechanism to throw SOAP Fault.
  </p>
  <p class="para">
   <div class="example" id="example-5347">
    <p><strong>示例 #2 Some examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #0000BB">$x</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapFault</span><span style="color: #007700">(</span><span style="color: #DD0000">"Server"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Some&nbsp;error&nbsp;message"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapServer</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'uri'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"http://test-uri/"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-soapfault.construct-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="soapserver.fault.html" class="methodname" rel="rdfs-seeAlso">SoapServer::fault()</a> - Issue SoapServer fault indicating an error</span></li>
    <li class="member"><span class="function"><a href="function.is-soap-fault.html" class="function" rel="rdfs-seeAlso">is_soap_fault()</a> - Checks if a SOAP call has failed</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>